package com.briup.ptp.web.controller;

import com.briup.ptp.entity.Slaughter;
import com.briup.ptp.service.SlaughterService;
import com.briup.ptp.utils.PTPException;
import com.briup.ptp.utils.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Classname SlautherController
 * @Description TODO
 * @Date 2024/2/23 16:30
 * @Created by 孙雅如
 * @Version v1.0.0
 */
@RestController
@RequestMapping("/slaughter")
@Api(tags = "屠宰信息管理")
public class SlaughterController {
    @Autowired
    private SlaughterService service;

    @ApiOperation("分页多条件查询生猪的屠宰场名称、屠宰日期、屠宰生猪种类、屠宰重量、检验检疫结果、屠宰人员")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页码",required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页大小",required = true),
            @ApiImplicitParam(name = "name", value = "屠宰场名字",required =false),
            @ApiImplicitParam(name = "pigSpecies", value = "屠宰生猪种类",required = false)
    })
    @GetMapping("/page")
    public Result slaughterQueryPage(Integer pageNum, Integer pageSize, String
            name, String pigSpecies) {
        PageInfo<Slaughter> slaughterPageInfo = service.SlaughterQueryPage( name, pigSpecies,pageNum, pageSize);

        return Result.success(slaughterPageInfo);
    }

    @ApiOperation("新增/修改屠宰信息")
    @PostMapping("/saveOrUpdate")
    public Result saveSlaughter(@RequestBody Slaughter slaughter) {
        service.saveSlaughter(slaughter);
        return Result.success();
    }

    @ApiOperation("修改屠宰信息")
    @PutMapping("/update/{id}")
    public Result updateSlaughter(@PathVariable Integer id){
        try {
            service.updateSlaughter(id);
        }catch (PTPException e){
            return  Result.error(e.getResultCode());
        }
        return Result.success();
    }

}
